{include file="header/index" /}
<style>
  .form-control {
    height: 33px;
  }
</style>
<div class="newContentBox">
  <div class="fixedFather">
      <div class="fix">
          添加用户组
          <span class="newNotice"><span class="newtext">*</span>为必填项</span>
          <div class="newFixBtnBox">
              <button type="button" class="newBtnDefault newBtnGray" onclick="returnBack(this)"> <i class="fa fa-mail-reply"></i>返回</button>
          </div>
      </div>
  </div>
  <form action="{:url('Authgroup/add')}" class="layui-form newListPart " name="userAdd" id="userAdd">
    <div class="newPart">
      <div class="newTitle">
        <i class="fa fa-address-book allColor icon"></i>	基本信息
      </div>
      <div class="newContent">
          <div class="layui-form-item cover_layui_f_i">
            <label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 用户组名称</label>
            <div class="layui-input-block cover_layui_i_b">
              <input type="text" id="title" type="text" name="title" required  lay-verify="required" placeholder="请输入用户组名称" autocomplete="off" class="layui-input">
            </div>	
          </div>
          <div class="layui-form-item cover_layui_f_i">
            <label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 角色</label>
            <div class="layui-input-block cover_layui_i_b">
              <select name="role" id="role" lay-verify="required">
                  {foreach $role as $k =>$v}
                  <option value="{$k}">{$v}</option>
                  {/foreach}									
              </select>
            </div>
          </div>
          <div class="layui-form-item cover_layui_f_i">
            <label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 状态</label>
            <div class="layui-input-block cover_layui_i_b">
                <input type="checkbox"  name="status" value="1" lay-skin="primary" title="默认开启" checked="true">
            </div>	
          </div>
      </div>
      <div class="layui-form-item ">
        <div class="layui-input-block cover_layui_i_b">
          <button class="layui-btn newBtnDefault newBtnPrimary" lay-submit lay-filter="formDemo">保存</button>
          <button type="reset" class="layui-btn newBtnDefault">重置</button>
        </div>
      </div>
    </div>
  </form>
</div>    
<script>
  var layer = layui.layer,
		element = layui.element,
		laydate = layui.laydate,
		laypage = layui.laypage,
		form = layui.form,
		upload = layui.upload,
		layedit = layui.layedit;
  form.render();
  //重置
  function reset() {
    top.layer.confirm('你确定要重置吗?', {
      btn: ['确定', '取消'] //按钮
    }, function () {
      $("#userAdd")[0].reset();
      top.layer.msg('重置成功', {
        icon: 1
      });
    });
  }
  var flag = false;
  form.on('submit(formDemo)', function (data) {
    if(flag){
    return false;
    }
    flag = true;
    console.log(data.field);
    $.post("{:url('Authgroup/add')}", data.field, function (e) {
      if (e.code == '1') {
        // console.log('11111')
        layer.msg(e.msg, {
          icon: 1,
          time: 2000
        }, function () {
          window.location.href = e.data
        });
      } else {      
        layer.msg(e.msg, {
          icon: 2,
          time: 2000
        });
      }
    }, 'json')
    return false;  
  })
</script>